package com.j2eefast.flowable.bpm.service;


import cn.hutool.core.util.IdUtil;
import com.j2eefast.flowable.bpm.entity.bpmCrmPreparationEntity;
import com.j2eefast.flowable.bpm.mapper.bpmCrmPreparationMapper;
import com.j2eefast.common.core.mutidatasource.annotaion.DataSource;
import com.j2eefast.common.core.page.Query;
import com.j2eefast.common.core.utils.PageUtil;
import com.j2eefast.common.core.utils.ToolUtil;
import com.j2eefast.framework.utils.Constant;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import javax.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;
import java.util.Map;
import java.util.Arrays;
/**
 *
 * 整备Service接口
 * @author: yhli
 * @date 2020-06-28 21:49
 */
@Service
public class bpmCrmPreparationService extends ServiceImpl<bpmCrmPreparationMapper,bpmCrmPreparationEntity> {

	@Resource
	private bpmCrmPreparationMapper bpmCrmPreparationMapper;

	/**
	 * mybaitis-plus 页面分页查询
     */
    @DataSource(name="FLOWABLE")
	public PageUtil findPage(Map<String, Object> params) {
        QueryWrapper<bpmCrmPreparationEntity> queryWrapper = new QueryWrapper<bpmCrmPreparationEntity>();
              String saleCode = (String) params.get("saleCode");
         queryWrapper.eq(ToolUtil.isNotEmpty(saleCode), "sale_code", saleCode);
                               String saleUserid = (String) params.get("saleUserid");
         queryWrapper.eq(ToolUtil.isNotEmpty(saleUserid), "sale_userid", saleUserid);
          String saleOrderNumber = (String) params.get("saleOrderNumber");
         queryWrapper.eq(ToolUtil.isNotEmpty(saleOrderNumber), "sale_order_number", saleOrderNumber);
          String outCarVin = (String) params.get("outCarVin");
         queryWrapper.eq(ToolUtil.isNotEmpty(outCarVin), "out_car_vin", outCarVin);
          String outCarVehicle = (String) params.get("outCarVehicle");
         queryWrapper.eq(ToolUtil.isNotEmpty(outCarVehicle), "out_car_vehicle", outCarVehicle);
             String preparationServicePlace = (String) params.get("preparationServicePlace");
         queryWrapper.eq(ToolUtil.isNotEmpty(preparationServicePlace), "preparation_service_place", preparationServicePlace);
          String preparationServiceType = (String) params.get("preparationServiceType");
         queryWrapper.eq(ToolUtil.isNotEmpty(preparationServiceType), "preparation_service_type", preparationServiceType);
             String preparationInvoiceNumber = (String) params.get("preparationInvoiceNumber");
         queryWrapper.eq(ToolUtil.isNotEmpty(preparationInvoiceNumber), "preparation_invoice_number", preparationInvoiceNumber);
          String preparationInvoiceFilepath = (String) params.get("preparationInvoiceFilepath");
         queryWrapper.eq(ToolUtil.isNotEmpty(preparationInvoiceFilepath), "preparation_invoice_filepath", preparationInvoiceFilepath);
          String preparationActualAmount = (String) params.get("preparationActualAmount");
         queryWrapper.eq(ToolUtil.isNotEmpty(preparationActualAmount), "preparation_actual_amount", preparationActualAmount);
  		Page<bpmCrmPreparationEntity> page = bpmCrmPreparationMapper.selectPage(new Query<bpmCrmPreparationEntity>(params).getPage(), queryWrapper);
		return new PageUtil(page);
    }

    /**
     * 自定义分页查询，含关联实体对像
     */
    @DataSource(name="FLOWABLE")
	public PageUtil findPage(Map<String, Object> params,bpmCrmPreparationEntity bpmCrmPreparationEntity) {
		Page<bpmCrmPreparationEntity> page = bpmCrmPreparationMapper.findPage(new Query<bpmCrmPreparationEntity>(params).getPage(), bpmCrmPreparationEntity,(String) params.get(Constant.SQL_FILTER))  ;
		return new PageUtil(page);
	}
	/**
     * 批量删除
     */
    @DataSource(name="FLOWABLE")
	@Transactional(rollbackFor = Exception.class)
	public boolean deletebpmCrmPreparationByIds(String[] ids) {
		return removeByIds(Arrays.asList(ids));
	}

	/**
     * 单个删除
     */
    @DataSource(name="FLOWABLE")
	public boolean deletebpmCrmPreparationById(String id) {
		return removeById(id);
	}

	/**
     * 保存
     */
    @DataSource(name="FLOWABLE")
	public boolean savebpmCrmPreparation(bpmCrmPreparationEntity bpmCrmPreparation){
        bpmCrmPreparation.setId(IdUtil.fastSimpleUUID());
        return save(bpmCrmPreparation);
    }

	/**
     * 修改根居ID
     */
    @DataSource(name="FLOWABLE")
	public boolean updatebpmCrmPreparationById(bpmCrmPreparationEntity bpmCrmPreparation) {
		return updateById(bpmCrmPreparation);
	}

	/**
     * 根居ID获取对象
     */
    @DataSource(name="FLOWABLE")
	public bpmCrmPreparationEntity getbpmCrmPreparationById(String id){
		return getById(id);
	}
}
